﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crosland.Automotriz.Core;
using System.Data.SqlClient;
namespace Crosland.Automotriz.Data.Dao.Linq
{
    public class clsT_Man_Modelo_ImagenDAO
    {

        private AutomotrizEntities ContextoDeObjs = new AutomotrizEntities();

        public bool Insertar(T_MAN_MODELO_IMAGEN Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("T_MAN_MODELO_IMAGEN", Obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }

        public bool Eliminar(T_MAN_MODELO_IMAGEN obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("T_MAN_MODELO_IMAGEN", obj);
                ContextoDeObjs.DeleteObject(obj);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }


        public bool Modificar(T_MAN_MODELO_IMAGEN obj)
        {
            try
            {
                ContextoDeObjs.AttachTo("T_MAN_MODELO_IMAGEN", obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
            }
            catch (Exception)
            {
                return false;

            }
            return true;
        }



    public List<T_MAN_MODELO_IMAGEN> ListarT_Man_filtro()
    {

        List<T_MAN_MODELO_IMAGEN> lista = new List<T_MAN_MODELO_IMAGEN>();
        try
        {
            var q = from m in ContextoDeObjs.T_MAN_MODELO_IMAGEN
                    select m;

            lista = q.ToList();
            



        }
        catch (Exception )
        {
        }
        return lista;
    }













    public int UltimoNumero()
    {
        int max = 0;

        try
        {
            max = ContextoDeObjs.T_MAN_MODELO_IMAGEN.Select(x => x.ID_IMAGEN).Max();

        }
        catch (Exception)
        {
            return max;
        }

        return max;

    }





    public IEnumerable<Object> listarT_Man_Modelo_Imagen(int id_modelo) {

        IEnumerable<Object> lista = new List<Object>();

        try
        {
            
            var q = from TM in ContextoDeObjs.TD_MODELO
                    from TMMI in ContextoDeObjs.T_MAN_MODELO_IMAGEN
                    where
                TMMI.ID_MODELO == TM.ID_MODELO &&
                 TMMI.ID_MODELO == id_modelo
                    select new
                    {
                        
                        TM.DES_MODELO,
                        TM.DES_MARCA,
                        TM.TIP_NUM_RUEDA,
                        TM.DES_NUM_RUEDA,
                        TMMI.DES_IMAGEN,
                        TMMI.ID_IMAGEN,
                        TMMI.ID_MODELO,
                       
                    };
            

            lista = q.ToList();


        }
        catch (Exception)
        {
            
        
        }

        return lista;

    }

















    public IEnumerable<Object> listarT_Man_Modelo_Imagen_like_marca(int id_modelo)
    {

        IEnumerable<Object> lista = new List<Object>();

        try
        {

            var q = from TM in ContextoDeObjs.TD_MODELO
                    from TMMI in ContextoDeObjs.T_MAN_MODELO_IMAGEN
                    where
                TMMI.ID_MODELO == TM.ID_MODELO &&
                 TMMI.ID_MODELO == id_modelo
                    select new
                    {

                        TM.DES_MODELO,
                        TM.DES_MARCA,
                        TM.TIP_NUM_RUEDA,
                        TM.DES_NUM_RUEDA,
                        TMMI.DES_IMAGEN,
                        TMMI.ID_IMAGEN,
                        TMMI.ID_MODELO,

                    };


            lista = q.ToList();


        }
        catch (Exception)
        {


        }

        return lista;

    }


      

    }
}
